﻿using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.ExceptionServices;
using System.Threading;
using Microsoft.CSharp;
using Microsoft.Xna.Framework;
using Mono.Cecil;
using Terraria.Localization;
using Terraria.ModLoader.Exceptions;
using Terraria.ModLoader.IO;

namespace Terraria.ModLoader
{
	// Token: 0x020001CA RID: 458
	internal class ModCompile
	{
		// Token: 0x06001308 RID: 4872 RVA: 0x0040F0C0 File Offset: 0x0040D2C0
		internal static void LoadReferences()
		{
			if (ModCompile.moduleReferences != null)
			{
				return;
			}
			ModCompile.moduleReferences = (from refName in Assembly.GetExecutingAssembly().GetReferencedAssemblies()
			select Assembly.Load(refName).Location into loc
			where loc != ""
			select loc).ToList<string>();
		}

		// Token: 0x06001309 RID: 4873 RVA: 0x0040F134 File Offset: 0x0040D334
		internal static bool BuildAll(string[] modFolders, ModCompile.IBuildStatus status)
		{
			ModCompile.<>c__DisplayClass7_0 <>c__DisplayClass7_ = new ModCompile.<>c__DisplayClass7_0();
			<>c__DisplayClass7_.modList = new List<LocalMod>();
			foreach (string modFolder in modFolders)
			{
				ModCompile.BuildingMod buildingMod = ModCompile.ReadProperties(modFolder, status);
				if (buildingMod == null)
				{
					return false;
				}
				<>c__DisplayClass7_.modList.Add(buildingMod);
			}
			<>c__DisplayClass7_.installedMods = (from mod in ModLoader.FindMods()
			where !<>c__DisplayClass7_.modList.Exists((LocalMod m) => m.Name == mod.Name)
			select mod).ToList<LocalMod>();
			<>c__DisplayClass7_.requiredFromInstall = new HashSet<LocalMod>();
			foreach (LocalMod mod3 in <>c__DisplayClass7_.modList)
			{
				<>c__DisplayClass7_.<BuildAll>g__Require|1(mod3);
			}
			<>c__DisplayClass7_.modList.AddRange(<>c__DisplayClass7_.requiredFromInstall);
			List<ModCompile.BuildingMod> list;
			try
			{
				ModLoader.EnsureDependenciesExist(<>c__DisplayClass7_.modList, true);
				ModLoader.EnsureTargetVersionsMet(<>c__DisplayClass7_.modList);
				List<LocalMod> source = ModLoader.Sort(<>c__DisplayClass7_.modList);
				list = source.OfType<ModCompile.BuildingMod>().ToList<ModCompile.BuildingMod>();
			}
			catch (ModSortingException ex)
			{
				ErrorLogger.LogDependencyError(ex.Message);
				return false;
			}
			int num = 0;
			foreach (ModCompile.BuildingMod mod2 in list)
			{
				status.SetProgress(num++, list.Count);
				if (!ModCompile.Build(mod2, status))
				{
					return false;
				}
			}
			return true;
		}

		// Token: 0x0600130A RID: 4874 RVA: 0x0040F2C0 File Offset: 0x0040D4C0
		internal static void BuildModCommandLine(string modFolder)
		{
			FileStream fileStream = ModCompile.AcquireConsoleBuildLock();
			try
			{
				if (!ModCompile.Build(modFolder, new ModCompile.ConsoleBuildStatus()))
				{
					Environment.ExitCode = 1;
				}
			}
			catch (Exception value)
			{
				Console.WriteLine(value);
				Environment.ExitCode = 1;
			}
			finally
			{
				fileStream.Close();
			}
		}

		// Token: 0x0600130B RID: 4875 RVA: 0x0040F31C File Offset: 0x0040D51C
		internal static bool Build(string modFolder, ModCompile.IBuildStatus status)
		{
			ModCompile.BuildingMod buildingMod = ModCompile.ReadProperties(modFolder, status);
			return buildingMod != null && ModCompile.Build(buildingMod, status);
		}

		// Token: 0x0600130C RID: 4876 RVA: 0x0040F340 File Offset: 0x0040D540
		private static ModCompile.BuildingMod ReadProperties(string modFolder, ModCompile.IBuildStatus status)
		{
			if (modFolder.EndsWith("\\") || modFolder.EndsWith("/"))
			{
				modFolder = modFolder.Substring(0, modFolder.Length - 1);
			}
			string fileName = Path.GetFileName(modFolder);
			status.SetStatus(Language.GetTextValue("tModLoader.MSReadingProperties") + fileName);
			BuildProperties buildProperties;
			try
			{
				buildProperties = BuildProperties.ReadBuildFile(modFolder);
			}
			catch (Exception arg)
			{
				ErrorLogger.LogBuildError(Language.GetTextValue("tModLoader.BuildErrorFailedLoadBuildTxt", Path.Combine(modFolder, "build.txt")) + Environment.NewLine + arg);
				return null;
			}
			string path = Path.Combine(ModLoader.ModPath, fileName + ".tmod");
			TmodFile modFile = new TmodFile(path)
			{
				name = fileName,
				version = buildProperties.version
			};
			return new ModCompile.BuildingMod(modFile, buildProperties, modFolder);
		}

		// Token: 0x0600130D RID: 4877 RVA: 0x0000FB8E File Offset: 0x0000DD8E
		private static byte[] ReadIfExists(string path)
		{
			if (!File.Exists(path))
			{
				return null;
			}
			return File.ReadAllBytes(path);
		}

		// Token: 0x0600130E RID: 4878 RVA: 0x0040F418 File Offset: 0x0040D618
		private static bool Build(ModCompile.BuildingMod mod, ModCompile.IBuildStatus status)
		{
			byte[] array = null;
			byte[] array2 = null;
			byte[] array3 = null;
			if (mod.properties.noCompile)
			{
				array2 = (array = ModCompile.ReadIfExists(Path.Combine(mod.path, "All.dll")));
				array3 = ModCompile.ReadIfExists(Path.Combine(mod.path, "All.pdb"));
				if (array == null)
				{
					array = ModCompile.ReadIfExists(Path.Combine(mod.path, "Windows.dll"));
					array2 = ModCompile.ReadIfExists(Path.Combine(mod.path, "Mono.dll"));
					array3 = ModCompile.ReadIfExists(Path.Combine(mod.path, "Windows.pdb"));
				}
				if (array == null || array2 == null)
				{
					ErrorLogger.LogDllBuildError(mod.path);
					return false;
				}
			}
			else
			{
				List<LocalMod> list = ModCompile.FindReferencedMods(mod.properties);
				if (list == null)
				{
					return false;
				}
				if (Program.LaunchParameters.ContainsKey("-eac"))
				{
					if (!ModLoader.windows)
					{
						ErrorLogger.LogBuildError("Edit and continue is only supported on windows");
						return false;
					}
					try
					{
						status.SetStatus("Loading pre-compiled Windows.dll with edit and continue support");
						string path = Program.LaunchParameters["-eac"];
						string path2 = Path.ChangeExtension(path, "pdb");
						array = File.ReadAllBytes(path);
						array3 = File.ReadAllBytes(path2);
						mod.properties.editAndContinue = true;
						goto IL_15D;
					}
					catch (Exception arg)
					{
						ErrorLogger.LogBuildError("Failed to load pre-compiled edit and continue dll " + arg);
						return false;
					}
				}
				status.SetStatus(Language.GetTextValue("tModLoader.MSCompilingWindows", mod));
				status.SetProgress(0, 2);
				ModCompile.CompileMod(mod, list, true, ref array, ref array3);
				IL_15D:
				if (array == null)
				{
					return false;
				}
				status.SetStatus(Language.GetTextValue("tModLoader.MSCompilingMono", mod));
				status.SetProgress(1, 2);
				ModCompile.CompileMod(mod, list, false, ref array2, ref array3);
				if (array2 == null)
				{
					return false;
				}
			}
			if (!ModCompile.VerifyName(mod.Name, array) || !ModCompile.VerifyName(mod.Name, array2))
			{
				return false;
			}
			status.SetStatus(Language.GetTextValue("tModLoader.MSBuilding") + mod + "...");
			status.SetProgress(0, 1);
			mod.modFile.AddFile("Info", mod.properties.ToBytes());
			if (ModCompile.Equal(array, array2))
			{
				mod.modFile.AddFile("All.dll", array);
				if (array3 != null)
				{
					mod.modFile.AddFile("All.pdb", array3);
				}
			}
			else
			{
				mod.modFile.AddFile("Windows.dll", array);
				mod.modFile.AddFile("Mono.dll", array2);
				if (array3 != null)
				{
					mod.modFile.AddFile("Windows.pdb", array3);
				}
			}
			foreach (string text in Directory.GetFiles(mod.path, "*", SearchOption.AllDirectories))
			{
				string text2 = text.Substring(mod.path.Length + 1);
				if (!mod.properties.ignoreFile(text2) && !(text2 == "build.txt") && !(text2 == ".gitattributes") && !(text2 == ".gitignore") && !text2.StartsWith(".git" + Path.DirectorySeparatorChar.ToString()) && !text2.StartsWith(".vs" + Path.DirectorySeparatorChar.ToString()) && !text2.StartsWith("bin" + Path.DirectorySeparatorChar.ToString()) && !text2.StartsWith("obj" + Path.DirectorySeparatorChar.ToString()) && (mod.properties.includeSource || !ModCompile.sourceExtensions.Contains(Path.GetExtension(text))) && !(Path.GetFileName(text) == "Thumbs.db"))
				{
					ModCompile.AddResource(mod.modFile, text2, text);
				}
			}
			WAVCacheIO.ClearCache(mod.Name);
			mod.modFile.Save();
			ModLoader.EnableMod(mod.Name);
			ModCompile.ActivateExceptionReporting();
			ModLoader.isModder = true;
			return true;
		}

		// Token: 0x0600130F RID: 4879 RVA: 0x0040F810 File Offset: 0x0040DA10
		private static void AddResource(TmodFile modFile, string relPath, string filePath)
		{
			if (relPath.EndsWith(".png") && relPath != "icon.png")
			{
				using (FileStream fileStream = File.OpenRead(filePath))
				{
					byte[] array = ImageIO.ToRawBytes(fileStream);
					if (array != null)
					{
						modFile.AddFile(Path.ChangeExtension(relPath, "rawimg"), array);
						return;
					}
				}
			}
			modFile.AddFile(relPath, File.ReadAllBytes(filePath));
		}

		// Token: 0x06001310 RID: 4880 RVA: 0x0000FBA0 File Offset: 0x0000DDA0
		internal static void ActivateExceptionReporting()
		{
			if (ModCompile.exceptionReportingActive)
			{
				return;
			}
			ModCompile.exceptionReportingActive = true;
			AppDomain.CurrentDomain.FirstChanceException += delegate(object sender, FirstChanceExceptionEventArgs exceptionArgs)
			{
				if (exceptionArgs.Exception.Source == "MP3Sharp")
				{
					return;
				}
				if (exceptionArgs.Exception.TargetSite.Name.StartsWith("doColors_Mode"))
				{
					return;
				}
				StackTrace stackTrace = new StackTrace(true);
				float soundVolume = Main.soundVolume;
				Main.soundVolume = 0f;
				Main.NewText(exceptionArgs.Exception.Message + exceptionArgs.Exception.StackTrace + " " + Language.GetTextValue("tModLoader.RuntimeErrorSeeLogsTxtForFullTrace"), Color.OrangeRed, false);
				ErrorLogger.Log(Language.GetTextValue("tModLoader.RuntimeErrorSilentlyCaughtException") + exceptionArgs.Exception.Message + exceptionArgs.Exception.StackTrace + stackTrace.ToString());
				Main.soundVolume = soundVolume;
			};
		}

		// Token: 0x06001311 RID: 4881 RVA: 0x0040F888 File Offset: 0x0040DA88
		private static bool VerifyName(string modName, byte[] dll)
		{
			AssemblyDefinition assemblyDefinition = AssemblyDefinition.ReadAssembly(new MemoryStream(dll));
			string name = assemblyDefinition.Name.Name;
			if (name != modName)
			{
				ErrorLogger.LogBuildError(Language.GetTextValue("tModLoader.BuildErrorModNameDoesntMatchAssemblyName", modName, name));
				return false;
			}
			if (modName.Equals("Terraria", StringComparison.InvariantCultureIgnoreCase))
			{
				ErrorLogger.LogBuildError(Language.GetTextValue("tModLoader.BuildErrorModNamedTerraria"));
				return false;
			}
			try
			{
				TypeDefinition typeDefinition = assemblyDefinition.MainModule.Types.Single(delegate(TypeDefinition x)
				{
					TypeReference baseType = x.BaseType;
					return ((baseType != null) ? baseType.FullName : null) == "Terraria.ModLoader.Mod";
				});
				string a = typeDefinition.Namespace.Split(new char[]
				{
					'.'
				})[0];
				if (a != modName)
				{
					ErrorLogger.LogBuildError(Language.GetTextValue("tModLoader.BuildErrorNamespaceFolderDontMatch"));
					return false;
				}
			}
			catch
			{
				ErrorLogger.LogBuildError(Language.GetTextValue("tModLoader.BuildErrorNoModClass"));
				return false;
			}
			return true;
		}

		// Token: 0x06001312 RID: 4882 RVA: 0x0040F97C File Offset: 0x0040DB7C
		private static bool Equal(byte[] a, byte[] b)
		{
			if (a.Length != b.Length)
			{
				return false;
			}
			for (int i = 0; i < a.Length; i++)
			{
				if (a[i] != b[i])
				{
					return false;
				}
			}
			return true;
		}

		// Token: 0x06001313 RID: 4883 RVA: 0x0040F9AC File Offset: 0x0040DBAC
		internal static List<LocalMod> FindReferencedMods(BuildProperties properties)
		{
			Dictionary<string, LocalMod> dictionary = new Dictionary<string, LocalMod>();
			if (!ModCompile.FindReferencedMods(properties, dictionary))
			{
				return null;
			}
			return dictionary.Values.ToList<LocalMod>();
		}

		// Token: 0x06001314 RID: 4884 RVA: 0x0040F9D8 File Offset: 0x0040DBD8
		private static bool FindReferencedMods(BuildProperties properties, Dictionary<string, LocalMod> mods)
		{
			foreach (string text in properties.RefNames(true))
			{
				if (!mods.ContainsKey(text))
				{
					TmodFile tmodFile = new TmodFile(Path.Combine(ModLoader.ModPath, text + ".tmod"));
					try
					{
						tmodFile.Read(TmodFile.LoadedState.Code, null);
					}
					catch (Exception ex)
					{
						ErrorLogger.LogBuildError(string.Concat(new object[]
						{
							"Mod reference ",
							text,
							" ",
							ex
						}));
						return false;
					}
					LocalMod localMod = new LocalMod(tmodFile);
					mods[text] = localMod;
					ModCompile.FindReferencedMods(localMod.properties, mods);
				}
			}
			return true;
		}

		// Token: 0x06001315 RID: 4885 RVA: 0x0040FAB0 File Offset: 0x0040DCB0
		private static void CompileMod(ModCompile.BuildingMod mod, List<LocalMod> refMods, bool forWindows, ref byte[] dll, ref byte[] pdb)
		{
			ModCompile.LoadReferences();
			bool flag = mod.properties.includePDB && forWindows;
			if (flag && !ModLoader.windows)
			{
				Console.WriteLine(Language.GetTextValue("tModLoader.BuildErrorPDBWindowsOnly"));
				flag = false;
			}
			string text = Path.Combine(ModLoader.ModPath, "compile_temp");
			Directory.CreateDirectory(text);
			List<string> list = new List<string>();
			list.AddRange(ModCompile.GetTerrariaReferences(text, forWindows));
			list.AddRange(from refDll in mod.properties.dllReferences
			select Path.Combine(mod.path, "lib/" + refDll + ".dll"));
			foreach (LocalMod localMod in refMods)
			{
				string text2 = Path.Combine(text, localMod + ".dll");
				File.WriteAllBytes(text2, localMod.modFile.GetMainAssembly(new bool?(forWindows)));
				list.Add(text2);
				foreach (string text3 in localMod.properties.dllReferences)
				{
					text2 = Path.Combine(text, text3 + ".dll");
					File.WriteAllBytes(text2, localMod.modFile.GetFile("lib/" + text3 + ".dll"));
					list.Add(text2);
				}
			}
			CompilerParameters compilerParameters = new CompilerParameters
			{
				OutputAssembly = Path.Combine(text, mod + ".dll"),
				GenerateExecutable = false,
				GenerateInMemory = false,
				TempFiles = new TempFileCollection(text, true),
				IncludeDebugInformation = flag
			};
			compilerParameters.ReferencedAssemblies.AddRange(list.ToArray());
			string[] array = (from file in Directory.GetFiles(mod.path, "*.cs", SearchOption.AllDirectories)
			where !mod.properties.ignoreFile(file.Substring(mod.path.Length + 1))
			select file).ToArray<string>();
			try
			{
				CompilerResults compilerResults;
				if (mod.properties.languageVersion == 6)
				{
					if (Environment.Version.Revision < 10000)
					{
						ErrorLogger.LogBuildError(Language.GetTextValue("tModLoader.BuildErrorDotNet45forCS6"));
						return;
					}
					compilerResults = ModCompile.RoslynCompile(compilerParameters, array);
				}
				else
				{
					Dictionary<string, string> providerOptions = new Dictionary<string, string>
					{
						{
							"CompilerVersion",
							"v" + mod.properties.languageVersion + ".0"
						}
					};
					compilerResults = new CSharpCodeProvider(providerOptions).CompileAssemblyFromFile(compilerParameters, array);
				}
				if (compilerResults.Errors.HasErrors)
				{
					ErrorLogger.LogCompileErrors(compilerResults.Errors, forWindows);
				}
				else
				{
					dll = File.ReadAllBytes(compilerParameters.OutputAssembly);
					dll = ModCompile.PostProcess(dll, forWindows);
					if (flag)
					{
						pdb = File.ReadAllBytes(Path.Combine(text, mod + ".pdb"));
					}
				}
			}
			finally
			{
				int j = 10;
				while (j > 0)
				{
					try
					{
						Directory.Delete(text, true);
						j = 0;
					}
					catch
					{
						Thread.Sleep(1);
						j--;
					}
				}
			}
		}

		// Token: 0x06001316 RID: 4886 RVA: 0x0040FDD8 File Offset: 0x0040DFD8
		private static IEnumerable<string> GetTerrariaReferences(string tempDir, bool forWindows)
		{
			ModCompile.LoadReferences();
			List<string> list = new List<string>(ModCompile.moduleReferences);
			if (forWindows == ModLoader.windows)
			{
				Assembly executingAssembly = Assembly.GetExecutingAssembly();
				list.Add(executingAssembly.Location);
				using (IEnumerator<string> enumerator = (from n in executingAssembly.GetManifestResourceNames()
				where n.EndsWith(".dll")
				select n).GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						string text = enumerator.Current;
						string text2 = Path.Combine(tempDir, Path.GetFileName(text));
						using (Stream manifestResourceStream = executingAssembly.GetManifestResourceStream(text))
						{
							using (Stream stream = File.Create(text2))
							{
								manifestResourceStream.CopyTo(stream);
							}
						}
						list.Add(text2);
					}
					return list;
				}
			}
			list.RemoveAll(delegate(string path)
			{
				string fileName = Path.GetFileName(path);
				return fileName == "FNA.dll" || fileName.StartsWith("Microsoft.Xna.Framework");
			});
			string text3 = Path.Combine(ModCompile.modCompileDir, forWindows ? "tModLoaderWindows.exe" : "tModLoaderMac.exe");
			list.Add(text3);
			string[] array;
			if (!forWindows)
			{
				(array = new string[1])[0] = "FNA.dll";
			}
			else
			{
				string[] array2 = new string[4];
				array2[0] = "Microsoft.Xna.Framework.dll";
				array2[1] = "Microsoft.Xna.Framework.Game.dll";
				array2[2] = "Microsoft.Xna.Framework.Graphics.dll";
				array = array2;
				array2[3] = "Microsoft.Xna.Framework.Xact.dll";
			}
			string[] source = array;
			list.AddRange(from f in source
			select Path.Combine(ModCompile.modCompileDir, f));
			AssemblyDefinition assemblyDefinition = AssemblyDefinition.ReadAssembly(text3);
			foreach (EmbeddedResource embeddedResource in from res in assemblyDefinition.MainModule.Resources.OfType<EmbeddedResource>()
			where res.Name.EndsWith(".dll")
			select res)
			{
				string text4 = Path.Combine(tempDir, Path.GetFileName(embeddedResource.Name));
				using (Stream resourceStream = embeddedResource.GetResourceStream())
				{
					using (Stream stream2 = File.Create(text4))
					{
						resourceStream.CopyTo(stream2);
					}
				}
				list.Add(text4);
			}
			return list;
		}

		// Token: 0x06001317 RID: 4887 RVA: 0x00410064 File Offset: 0x0040E264
		private static CompilerResults RoslynCompile(CompilerParameters compileOptions, string[] files)
		{
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			string modCompileDir = Path.Combine(directoryName, "ModCompile");
			Assembly assembly = Assembly.LoadFile(Path.Combine(modCompileDir, "RoslynWrapper.dll"));
			AppDomain.CurrentDomain.AssemblyResolve += delegate(object o, ResolveEventArgs args)
			{
				string name = new AssemblyName(args.Name).Name;
				string path = Path.Combine(modCompileDir, name + ".dll");
				if (!File.Exists(path))
				{
					return null;
				}
				return Assembly.LoadFile(path);
			};
			CompilerResults compilerResults = (CompilerResults)assembly.GetType("Terraria.ModLoader.RoslynWrapper").GetMethod("Compile").Invoke(null, new object[]
			{
				compileOptions,
				files
			});
			if (!compilerResults.Errors.HasErrors && compileOptions.IncludeDebugInformation)
			{
				assembly.GetType("Terraria.ModLoader.RoslynPdbFixer").GetMethod("Fix").Invoke(null, new object[]
				{
					compileOptions.OutputAssembly
				});
			}
			return compilerResults;
		}

		// Token: 0x06001318 RID: 4888 RVA: 0x00410134 File Offset: 0x0040E334
		private static FileStream AcquireConsoleBuildLock()
		{
			string path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "/ModCompile/buildlock";
			bool flag = true;
			FileStream result;
			for (;;)
			{
				try
				{
					result = new FileStream(path, FileMode.OpenOrCreate);
				}
				catch (IOException)
				{
					if (flag)
					{
						Console.WriteLine("Waiting for other builds to complete");
						flag = false;
					}
					continue;
				}
				break;
			}
			return result;
		}

		// Token: 0x06001319 RID: 4889 RVA: 0x0041018C File Offset: 0x0040E38C
		private static AssemblyNameReference GetOrAddSystemCore(ModuleDefinition module)
		{
			AssemblyNameReference assemblyNameReference = module.AssemblyReferences.SingleOrDefault((AssemblyNameReference r) => r.Name == "System.Core");
			if (assemblyNameReference == null)
			{
				AssemblyName name = Assembly.GetAssembly(typeof(Enumerable)).GetName();
				assemblyNameReference = new AssemblyNameReference(name.Name, name.Version)
				{
					Culture = name.CultureInfo.Name,
					PublicKeyToken = name.GetPublicKeyToken(),
					HashAlgorithm = name.HashAlgorithm
				};
				module.AssemblyReferences.Add(assemblyNameReference);
			}
			return assemblyNameReference;
		}

		// Token: 0x0600131A RID: 4890 RVA: 0x00410224 File Offset: 0x0040E424
		private static byte[] PostProcess(byte[] dll, bool forWindows)
		{
			if (forWindows)
			{
				return dll;
			}
			AssemblyDefinition assemblyDefinition = AssemblyDefinition.ReadAssembly(new MemoryStream(dll));
			AssemblyNameReference assemblyNameReference = null;
			foreach (ModuleDefinition moduleDefinition in assemblyDefinition.Modules)
			{
				foreach (TypeDefinition typeDefinition in moduleDefinition.Types)
				{
					foreach (MethodDefinition methodDefinition in typeDefinition.Methods)
					{
						foreach (CustomAttribute customAttribute in methodDefinition.CustomAttributes)
						{
							if (customAttribute.AttributeType.FullName == "System.Runtime.CompilerServices.ExtensionAttribute")
							{
								TypeReference attributeType = customAttribute.AttributeType;
								AssemblyNameReference scope;
								if ((scope = assemblyNameReference) == null)
								{
									scope = (assemblyNameReference = ModCompile.GetOrAddSystemCore(moduleDefinition));
								}
								attributeType.Scope = scope;
							}
						}
					}
				}
			}
			MemoryStream memoryStream = new MemoryStream();
			assemblyDefinition.Write(memoryStream, new WriterParameters
			{
				SymbolWriterProvider = AssemblyManager.SymbolWriterProvider.instance
			});
			return memoryStream.ToArray();
		}

		// Token: 0x04001448 RID: 5192
		private static readonly string modCompileDir = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "ModCompile");

		// Token: 0x04001449 RID: 5193
		internal static IList<string> sourceExtensions = new List<string>
		{
			".csproj",
			".cs",
			".sln"
		};

		// Token: 0x0400144A RID: 5194
		private static IList<string> moduleReferences;

		// Token: 0x0400144B RID: 5195
		private static bool exceptionReportingActive;

		// Token: 0x020001CB RID: 459
		public interface IBuildStatus
		{
			// Token: 0x0600131D RID: 4893
			void SetProgress(int i, int n);

			// Token: 0x0600131E RID: 4894
			void SetStatus(string msg);
		}

		// Token: 0x020001CC RID: 460
		private class ConsoleBuildStatus : ModCompile.IBuildStatus
		{
			// Token: 0x0600131F RID: 4895 RVA: 0x00006B58 File Offset: 0x00004D58
			public void SetProgress(int i, int n)
			{
			}

			// Token: 0x06001320 RID: 4896 RVA: 0x0000FBD9 File Offset: 0x0000DDD9
			public void SetStatus(string msg)
			{
				Console.WriteLine(msg);
			}
		}

		// Token: 0x020001CD RID: 461
		private class BuildingMod : LocalMod
		{
			// Token: 0x06001322 RID: 4898 RVA: 0x0000FBE1 File Offset: 0x0000DDE1
			public BuildingMod(TmodFile modFile, BuildProperties properties, string path) : base(modFile, properties)
			{
				this.path = path;
			}

			// Token: 0x0400144C RID: 5196
			public string path;
		}
	}
}
